﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProjControleBLL;
using ProjControleDAL;
using ProjControleModelos;
namespace ProjControle
{
    public partial class frm_login : Form
    {
        public frm_login()
        {
            InitializeComponent();
        }
        //String login;
        #region Métodos
        public void carregaCombo()
        {
            try
            {
                Dados objDados = new Dados();
                objDados.preencheCombo(cbLogin, "funcionario", "cod_funcionario", "login_funcionario", "", "login_funcionario");
                objDados = null;
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        private void frm_login_Load(object sender, EventArgs e)
        {
            carregaCombo();
        }

        private void bLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbLogin.SelectedIndex != -1 && tbSenha.Text != "")
                {
                    FuncionarioBLL objBLL = new FuncionarioBLL();
                    int codigo = int.Parse(cbLogin.SelectedValue.ToString());
                    objBLL.localizar(codigo, tbSenha.Text);
                    if (tbSenha.Text.Trim() == MGlobal.senha)
                    {
                        //MessageBox.Show("Bem vindo " + MGlobal.login);
                        this.Hide();
                        this.Visible = false;
                        frm_inicial frm = new frm_inicial();
                        frm.ShowDialog();
                        this.Close();
                    }
                    else
                        MessageBox.Show("Senha Invalida...", "Valida", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    tbSenha.Focus();
                    
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void bCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
